//
//  LSPolicyLawsTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/27.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSPolicyLawsTableViewCell.h"
#import "LSNewsViewModel.h"

@interface LSPolicyLawsTableViewCell ()
@property (nonatomic, strong) UIImageView *greenRightArrowImageView;
@property (nonatomic, strong) UILabel *mainTitleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIView *customerContentView;
@end

@implementation LSPolicyLawsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = hexColor(EEEEEE);
        UIView *customerContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, ScreenWidth, LSPolicyLawsTableViewCellHeight-5)];
        self.customerContentView = customerContentView;
        customerContentView.backgroundColor = UIColor.whiteColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:customerContentView];
        [self.contentView addSubview:self.greenRightArrowImageView];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.mainTitleLabel];
    }
    return self;
}

- (void)setMainTitleText:(NSString *)mainTitleText {
    _mainTitleText = mainTitleText;
    self.mainTitleLabel.text = mainTitleText;
}

- (void)setTimeText:(NSString *)timeText {
    _timeText = timeText;
    self.timeLabel.text = timeText;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    WS
    if (highlighted) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    WS
    if (selected) {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
        }
    } else {
        if (animated) {
            [UIView animateWithDuration:0.5 animations:^{
                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
            }];
        } else {
            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
        }
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.customerContentView.mas_right).with.offset(-20);
        make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
    }];
    [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.customerContentView.mas_left).with.offset(44);
        make.right.equalTo(weakSelf.customerContentView.mas_right).with.offset(-80);
        make.centerY.equalTo(weakSelf.customerContentView.mas_centerY);
    }];
}

- (UIImageView *)greenRightArrowImageView {
    if (!_greenRightArrowImageView) {
        _greenRightArrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(18, 12+5, 16, 16)];
        _greenRightArrowImageView.image = [UIImage imageNamed:@"greenRightArrow"];
    }
    return _greenRightArrowImageView;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:10];
        _timeLabel.textColor = hexColor(333333);
        _timeLabel.textAlignment = NSTextAlignmentRight;
    }
    return _timeLabel;
}

- (UILabel *)mainTitleLabel {
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
        _mainTitleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
        _mainTitleLabel.textColor = hexColor(333333);
    }
    return _mainTitleLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
